import Vue from 'vue'
import Router from 'vue-router'


Vue.use(Router)

const router = new Router({
  routes: [
    {
      path: '/',
      name:'home-page',
      component:require('@/components/HomePage').default,
	  meta:{
		  needLogin:true
	  }
    },
    {
        path:'/home',
        name:'home-page',
        component:require('@/components/HomePage').default,
	  meta:{
		  needLogin:true
	  }
    }, 
	{
        path:'/test',
        name:'test-page',
        component:require('@/components/TestPage').default,
	  meta:{
		  needLogin:true
	  }
    }, 
	{
        path:'/books',
        name:'books-page',
        component:require('@/components/BookPage').default,
	  meta:{
		  needLogin:true
	  }
    },
	{
	    path:'/users',
	    name:'users-page',
	    component:require('@/components/UserPage/UserPage').default,
	  meta:{
		  needLogin:true
	  }
	},
	{
	    path:'/sysusers',
	    name:'users-page',
	    component:require('@/components/SystemPage/SystemUserPage').default,
	  meta:{
		  needLogin:true
	  }
	},
	{
	    path:'/setting',
	    name:'setting-page',
	    component:require('@/components/SystemPage/SettingPage').default,
	  meta:{
		  needLogin:true
	  }
	},
	{
	    path:'/lends',
	    name:'lend-page',
	    component:require('@/components/LendPage').default,
	  meta:{
		  needLogin:true
	  }
	},
    {
        path:'*',
        redirect:'/'
    }
  ]
})

router.beforeEach(function(to,from,next){
		if(to.meta.needLogin){
			console.log(Vue.localStorage.get('userAccount') )
			if(Vue.localStorage.get('userAccount')){
				next();
			}else{
				next({name:'login'})
			}
		}else{
			next();
		}
	})

export default  router
